package cn.yunyichina.reservation.constant;

/**
 * Created by Lullaby on 2016/8/18.
 */
public class HttpResponse {

    private static final String OKAY_CODE = "0";

    private static final String OKAY_MESSAGE = "okay";

    private static final String ERROR_CODE = "-1";

    private static final String ERROR_MESSAGE = "error";

    private Meta meta;

    private Object data;

    public HttpResponse() {
        this.meta = new Meta(OKAY_CODE, OKAY_MESSAGE);
    }

    public HttpResponse success() {
        this.meta = new Meta(OKAY_CODE, OKAY_MESSAGE);
        return this;
    }

    public HttpResponse success(String message) {
        this.meta = new Meta(OKAY_CODE, message);
        return this;
    }

    public HttpResponse success(String code, String message) {
        this.meta = new Meta(code, message);
        return this;
    }

    public HttpResponse success(Object data) {
        this.meta = new Meta(OKAY_CODE, OKAY_MESSAGE);
        this.data = data;
        return this;
    }

    public HttpResponse failure() {
        this.meta = new Meta(ERROR_CODE, ERROR_MESSAGE);
        return this;
    }

    public HttpResponse failure(String message) {
        this.meta = new Meta(ERROR_CODE, message);
        return this;
    }

    public HttpResponse failure(String code, String message) {
        this.meta = new Meta(code, message);
        return this;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Meta getMeta() {
        return meta;
    }

    public Object getData() {
        return data;
    }

    public static class Meta {
        private String code;
        private String message;

        public Meta(String code, String message) {
            this.code = code;
            this.message = message;
        }

        public String getCode() {
            return code;
        }

        public String getMessage() {
            return message;
        }
    }

}
